package com.iteaj.network.test.server.line.protocol;

import cn.hutool.json.JSONUtil;
import com.iteaj.network.server.protocol.ClientInitiativeProtocol;
import com.iteaj.network.test.MessageCreator;
import com.iteaj.network.test.MessageEntity;
import com.iteaj.network.test.TestProtocolType;
import com.iteaj.network.test.server.line.LineMessage;

/**
 * 设备请求平台的测试协议
 */
public class LineDeviceRequestProtocol extends ClientInitiativeProtocol<LineMessage> {

    private MessageEntity content;

    public LineDeviceRequestProtocol(LineMessage requestMessage) {
        super(requestMessage);
    }

    @Override
    protected LineMessage doBuildResponseMessage() {
        return MessageCreator.lineBuild(getEquipCode(), TestProtocolType.CIReq, requestMessage());
    }

    @Override
    protected void doBuildRequestMessage(LineMessage requestMessage) {
        byte[] message = requestMessage.getMessage();
        this.content = JSONUtil.toBean(new String(message), MessageEntity.class);
    }


    @Override
    public TestProtocolType protocolType() {
        return TestProtocolType.CIReq;
    }
}
